<?php

namespace app\admin\controller\seo;

use app\common\controller\Backend;

use think\Config;
/**
 * 文章描述
 *
 * @icon fa fa-circle-o
 */
class Release extends Backend
{
    
    /**
     * Describe模型对象
     * @var \app\admin\model\Describe
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
		$adminID = $this->auth->id ;
		
		//文章描述
        $this->describe = new \app\admin\model\Describe;
		$describez = $this->describe->where('uid','=',$adminID)->select();
		
		if(!empty($describez)){
			$mydesc = array();
			foreach($describez as $v){
				//获取 文章描述
				$mydesc[] = $v['describes'];
			}
			$this->miaoshu = $mydesc;
		}
		
		//***************
		
		//模板
		$this->templets = new \app\admin\model\Templets;
		$templets = $this->templets->where('uid','=',$adminID)->select();
		if(!empty($templets)){
			$moban = array();
			foreach ($templets as $row) {
				$moban[] = $row['mycontent'];
			}
			$this->moban = $moban;
		}

		//***************
		
		//关键词  地区 词头 词尾 主词
        $this->word = new \app\admin\model\Word;
		$word = $this->word->where('uid','=',$adminID)->select();
		if(!empty($word)){
			foreach($word as $v){
				//反序列化
				$prehead =  unserialize($v['prehead']);
				$prefix =  unserialize($v['prefix']);
				$main =  unserialize($v['main']);
				$suffix =  unserialize($v['suffix']);
				foreach($prehead as $sw){
					//除去没启用的
					if($sw['show'] == 1){
						$preheadinfo[] = $sw['prehead'];
					}
				}
				foreach($prefix as $sw){
					//除去没启用的
					if($sw['show'] == 1){
						$prefixinfo[] = $sw['prefix'];
					}
				}
				foreach($main as $sw){
					//除去没启用的
					if($sw['show'] == 1){
						$maininfo[] = $sw['main'];
					}
				}
				foreach($suffix as $sw){
					//除去没启用的
					if($sw['show'] == 1){
						$suffixinfo[] = $sw['suffix'];
					}
				}
			}	
			//地区
			$this->preheadinfo = $preheadinfo;
			//词头
			$this->prefixinfo = $prefixinfo;
			//词尾
			$this->maininfo = $maininfo;
			//主词
			$this->suffixinfo = $suffixinfo;	
		}
		
		//***************
		
		//文章段落
		$this->section = new \app\admin\model\Section;
		$section = $this->section->where('uid','=',$adminID)->select();
		if(!empty($section)){
			$duanluo = array();
			foreach($section as $v){
				$duanluo[] = $v['content'];
			}
			$this->duanluo = $duanluo;			
		}

		//***************
		
		//句子库
		$this->phrases = new \app\admin\model\Phrases;
		$phrases = $this->phrases->where('uid','=',$adminID)->select();
		if(!empty($phrases)){
			$juzi = array();
			foreach($phrases as $v){
				$juzi[] = $v['content'];
			}
			$this->juzi = $juzi;			
		}

		//***************
		
		//图片
		$this->prints = new \app\admin\model\Prints;
		$prints = $this->prints->where('uid','=',$adminID)->select();
		if(!empty($prints)){
			$tupian = array();
			foreach($prints as $v){
				if($v['status'] == 1){
					$tupian[] = $v['printsimage'];
				}
			}
			$this->tupian = $tupian;			
		}
	
		
    }
    
    /**
     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
     */
    

    /**
     * 查看
     */
    public function index()
    {
		//获取用户ID
		$adminID = $this->auth->id ;
	 	$begininfo = $this->begin = new \app\admin\model\Begin;
		$begins =$begininfo ->where('uid','=',$adminID)->select();

		if(!empty($begins)){
		
			$bgs = array();
			foreach($begins as $v){
				$bgs[] = array($v['zc'],$v['ms'],$v['ld'],$v['jz'],$v['mb'],$v['uid'],$v['is_begin'],$v['retime']);
			}
			$bgsnum = count($bgs); 
			if ($this->request->isAjax())
			{
				for($c=0;$c<$bgsnum;$c++){
					$agotime = $bgs[$c][7]; 
					$nowtime = time();
					$mytimes = $nowtime - $agotime;
					$mydays = $mytimes/86400;
					$mydaysz = intval($mydays); 
					 if($bgs[$c][6] == 1 and $mydays < 19){
						//状态
						$zhuangtai = '启动';
						//获取当时存入的戳  获取现在的时间戳  总共2592
						
						//进度
						$jda = $mytimes/600;
						$jdb = $jda/2592;
						$jindu = round($jdb*100).'%';
						//剩余天数
						$ts = 18 - $mydays;
						if($ts == 0){
							$tianshu = '最后一天';
						}else{
							$tianshu = intval($ts);
						}
						
					}else{
						//状态
						$zhuangtai = '未启动';
						//进度
						$jindu = '未启动';
						//剩余天数
						$tianshu = '未启动';
					} 

					$list[] = array('username'=>'苏州','zhuci'=>$bgs[$c][0],'miaoshu'=>$bgs[$c][1],'duanluo'=>$bgs[$c][2],'juzi'=>$bgs[$c][3],'muban'=>$bgs[$c][4],'jindu'=>$jindu,'tianshu'=>$tianshu,'zhuangtai'=>$zhuangtai);
				}
				
				
				//分页数
				$total = 1;
				$result = array("total" => $total, "rows" => $list);

				return json($result);
			}			
		}

        return $this->view->fetch();
    }
	
	
	public function mymyinfo(){

		$adminID = $this->auth->id ;
		$myusettime = model('userinfo')->where('uid','=',$adminID)->find();
		$newtime = time();
		
		//还要判断 是否在套餐时间内  userinfo表里面的 end_timne 
		if($newtime < $myusettime['end_time']){
			$usebegin = $this->begin = new \app\admin\model\Begin;
			$mybegins = $usebegin ->where('uid','=',$adminID)->select();

			if(!empty($mybegins)){
				$bgnum = count($mybegins) - 1;
				$agotime = $mybegins[$bgnum]['retime'];  // 算进度
				$mytimes = $newtime - $agotime;
				$jda = $mytimes/600;
				$jdb = $jda/2592;
				$jindu = round($jdb*100);
				// 判断最新的一条，进度为33%可以发新的一条  
				if($jindu > 1){
					$zbready = $this->zbready();
					if($zbready['mainnum'] < 2 or $zbready['mainnum'] = ''){
						$return = 6;	
					}else if($zbready['miaoshu'] < 2 or $zbready['miaoshu'] = ''){
						$return = 2;	
					}else if($zbready['duanluo'] < 100 or $zbready['duanluo'] = ''){
						$return = 3;	
					}else if($zbready['juzi'] < 15 or $zbready['juzi'] = '' ){
						$return = 4;	
					}else if($zbready['muban'] < 3 or $zbready['muban'] = ''){
						$return = 5;	
					}else{
						//启动
						//写入 begin
						$zbready = $this->zbready();
						$data = ['uid' => $adminID, 'zc' => $zbready['mainnum'],'ms' => $zbready['miaoshu'],'ld' => $zbready['duanluo'],'jz'=>$zbready['juzi'],'mb'=>$zbready['muban'],'is_begin'=>1,'retime'=>$newtime];
						$result = $usebegin->insert($data);
						if(!empty($result)){
							$beginz = $this->begin();
							$return = $beginz;								
						}
						
					}
				}else{
					$return = 9;	  //不满足 进度
				}
			}else{
				//不存在  启动限制 
				$zbready = $this->zbready();
				if($zbready['mainnum'] < 2 or $zbready['mainnum'] = ''){    
					$return = 6;	
				}else if($zbready['miaoshu'] < 2 or $zbready['miaoshu'] = ''){  
					$return = 2;	
				}else if($zbready['duanluo'] < 100 or $zbready['duanluo'] = ''){  
					$return = 3;	
				}else if($zbready['juzi'] < 15 or $zbready['juzi'] = '' ){ 
					$return = 4;	
				}else if($zbready['muban'] < 3 or $zbready['muban'] = ''){  
					$return = 5;	
				}else{
					//启动
					//写入 begin 
					$zbready = $this->zbready();
					$data = ['uid' => $adminID, 'zc' => $zbready['mainnum'],'ms' => $zbready['miaoshu'],'ld' => $zbready['duanluo'],'jz'=>$zbready['juzi'],'mb'=>$zbready['muban'],'is_begin'=>1,'retime'=>$newtime];
					$result = $usebegin->insert($data);
					if(!empty($result)){	
						$beginz = $this->begin();	
						$return = $beginz;	
					}
				}		
			}
			
		}else{
			$return = 8;	
		}
		echo json_encode($return);
	}
	
	
	
	/**
	 * 查询 启动数据
	 */
	private function zbready(){
		$adminID = $this->auth->id ;
		$word = $this->word->where('uid','=',$adminID)->select();
		$maininfo =  unserialize($word[0]['main']);
		foreach($maininfo as $v){
			if($v['show'] == 1){
				$main[] = $v['main'];
			}
		}
		$mainnum = count($main);
		
		//描述
		$describe = $this->describe->where('uid','=',$adminID)->select();
		$miaoshu = count($describe);
			
		//段落数
		$section = $this->section->where('uid','=',$adminID)->select();
		$duanluo = count($section);
			
		//句子库
		$phrases = $this->phrases->where('uid','=',$adminID)->select();
		$juzi = count($phrases);
			
		//模板
		$templets = $this->templets->where('uid','=',$adminID)->select();
		$muban = count($templets);
		$myarr = array('mainnum' => $mainnum,'miaoshu' => $miaoshu,'duanluo' => $duanluo,'juzi' => $juzi,'muban' => $muban);
		return $myarr;
	}
	
	
	/**
	 * 启动 
	 */
	private function begin(){
		//随机选择数据库 
	 	$configure = Config::get('configure');
		$sqlnum = count($configure);
		$myval = rand(1,$sqlnum)-1;
		
		$brip = $configure[$myval]['useip'];
		$brname = $configure[$myval]['usename'];
		$brpwd = $configure[$myval]['usepwd']; 
		//随机把生成的文章 写入不同数据库的 不同表中	
		$connect=mysqli_connect($brip,$brname,$brpwd);

		//查询数据库表
		$sql="SHOW TABLES FROM $brname";
		

		//发送SQL语句
		//$isset=mysqli_query($connect,$sql); 
		$result=mysqli_query($connect,$sql); 
		if(!empty(mysqli_fetch_all($result))){
			//存在 查看数据库表明    查询数据条数 是否满 30W
			mysqli_select_db($connect, $brname );
			$sql = "SHOW TABLES";
			$result = mysqli_query($connect,$sql);	
			$rows = mysqli_fetch_all($result);	
			//查看最新的 表名
			$rowsnum = count($rows) -1;
			$mythwname = $rows[$rowsnum];			
			//ORDER BY `id` DESC LIMIT 1
			//SELECT  * FROM `table_name`  
			$sql = "SELECT id FROM $mythwname[0] ORDER BY `id` DESC LIMIT 1";	
			$results = mysqli_query($connect,$sql);	
			$rowr = mysqli_fetch_row($results);	

			$rowcount = $rowr[0];	
			$setnum = Config::get('setnum');
			if($rowcount < $setnum){
				//准备数据
				$time = time();
				//存在 拼接插入2592一条数据
				$resql = "INSERT INTO $mythwname[0] (uid, keyword, title, descriptions, classify, myarticle, addtime) VALUES ";
					for($i=0;$i<2592;$i++){
						$adminID = $this->auth->id ;  //uid
						$keyinfo = $this->randomkeymain(); //关键词
						$btinfo = $this->randbt(); //标题
						$descinfo = $this->randommydesc(); //描述
						$classify = 1; //类别
						$wzinfo = $this->randwz();
						$time += 600;
						if($i==0){
							$resql.="('$adminID','$keyinfo','$btinfo','$descinfo','$classify','$wzinfo','$time')";
						}else{
							$resql.=",('$adminID','$keyinfo','$btinfo','$descinfo','$classify','$wzinfo','$time')";
						} 
					}
				$myresql=mysqli_query($connect,$resql);
				
				if($myresql){
					//返回成功 信息
					return 1;	
				}else{
					//返回失败 信息
					return 10;
				}
			}else{
				$rowcountnum = $rowcount + 1;
				$newnum = count($rows)+1;
				$newthwname = "mythw".$newnum;
				//新建数据库  写入数据
				$sql = "CREATE TABLE $newthwname (
					id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
					uid INT NOT NULL,
					keyword VARCHAR(30) NOT NULL,
					title VARCHAR(30) NOT NULL,
					descriptions VARCHAR(255) NOT NULL,
					classify VARCHAR(10) NOT NULL,
					myarticle text NOT NULL,
					addtime CHAR(10) NOT NULL
				) AUTO_INCREMENT = $rowcountnum";
				$result=mysqli_query($connect,$sql);
				if($result){
					//成功后 插入数据
					//准备数据
					$time = time();
					//存在 拼接插入2592一条数据
					$resql = "INSERT INTO $newthwname (uid, keyword, title, descriptions, classify, myarticle, addtime) VALUES ";
						for($i=0;$i<2592;$i++){
							$adminID = $this->auth->id ;  //uid
							$keyinfo = $this->randomkeymain(); //关键词
							$btinfo = $this->randbt(); //标题
							$descinfo = $this->randommydesc(); //描述
							$classify = 1; //类别
							$wzinfo = $this->randwz();
							$time += 600;
							if($i==0){
								$resql.="('$adminID','$keyinfo','$btinfo','$descinfo','$classify','$wzinfo','$time')";
							}else{
								$resql.=",('$adminID','$keyinfo','$btinfo','$descinfo','$classify','$wzinfo','$time')";
							} 
						}
					$myresql=mysqli_query($connect,$resql);
					
					if($myresql){
						//返回成功 信息
						return 1;		
					}else{
						//返回失败 信息
						return 10;
					} 
				}else{
					return 11;
				}
			}
		}else{
			//不存在 新建   mythw1（固定）
			mysqli_select_db($connect, $brname );
			$sql = "CREATE TABLE mythw1 (
					id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
					uid INT NOT NULL,
					keyword VARCHAR(30) NOT NULL,
					title VARCHAR(30) NOT NULL,
					descriptions VARCHAR(255) NOT NULL,
					classify VARCHAR(10) NOT NULL,
					myarticle text NOT NULL,
					addtime CHAR(10) NOT NULL
				)";
			$result=mysqli_query($connect,$sql);
			if($result){
					//准备数据
					$time = time();
					//存在 拼接插入3024一条数据
					$resql = "INSERT INTO mythw1 (uid, keyword, title, descriptions, classify, myarticle, addtime) VALUES ";
						for($i=0;$i<3024;$i++){
							$adminID = $this->auth->id ;  //uid
							$keyinfo = $this->randomkeymain(); //关键词
							$btinfo = $this->randbt(); //标题
							$descinfo = $this->randommydesc(); //描述
							$classify = 1; //类别
							$wzinfo = $this->randwz();
							$time += 600;
							if($i==0){
								$resql.="('$adminID','$keyinfo','$btinfo','$descinfo','$classify','$wzinfo','$time')";
							}else{
								$resql.=",('$adminID','$keyinfo','$btinfo','$descinfo','$classify','$wzinfo','$time')";
							} 
						}
					$myresql=mysqli_query($connect,$resql);
					
					if($myresql){
						//返回成功 信息
						return 1;
					}else{
						//返回失败 信息
						return 10;
					} 		
			}else{
				return 11;
			}
				
		}
		
	}
	
	
	/**
	 * 随机地区 
	 */
	
	private function randdq(){
		$preheadinfo = $this->preheadinfo;
		$headnum = count($preheadinfo);
		for($a=0;$a<$headnum;$a++){
			$valnum = rand(1,$headnum) - 1; 
			//地区
			$bta =  $preheadinfo[$valnum];
		}
		return $bta;
	}

	/**
	 * 随机词头 
	 */
	
	private function randct(){
		$prefixinfo = $this->prefixinfo;
		$fixnum = count($prefixinfo);
		for($a=0;$a<$fixnum;$a++){
			$valnum = rand(1,$fixnum) - 1; 
			//词头
			$btb =  $prefixinfo[$valnum];
		}
		return $btb;
	}	
	
	/**
	 * 随机主词 
	 */
	
	private function randzc(){
		$maininfo = $this->maininfo;
		$mainnum = count($maininfo);
		for($a=0;$a<$mainnum;$a++){
			$valnum = rand(1,$mainnum) - 1; 
			//主词
			$btc =  $maininfo[$valnum];
		}
		return $btc;
	}
	
	/**
	 * 随机词尾
	 */
	
	private function randcw(){
		$suffixinfo = $this->suffixinfo;
		$sufnum = count($suffixinfo);
		for($a=0;$a<$sufnum;$a++){
			$valnum = rand(1,$sufnum) - 1; 
			//词尾
			$btd =  $suffixinfo[$valnum];
		}
		return $btd;
	}
	
	/**
	 * 随机标题  
	 * 地区+主词
	 * 词头+主词
	 * 主词+词尾
	 * 地区+主词+词尾
	 * 地区+词头+主词
	 * 词头+主词+词尾
	 * 地区+词头+主词+词尾
	 */
	
	private function randbt(){
		$keynum= rand(1,7);
		if($keynum == 1){
			//词头+主词
			$myct = $this->randct();
			$myzc = $this->randzc();
			$keymain = $myct.$myzc;
		}else if($keynum == 2){
			//主词+词尾
			$myzc = $this->randzc();
			$mycw = $this->randcw();
			$keymain = $myzc.$mycw;
		}else if($keynum == 3){
			//地区+主词
			$mydq = $this->randdq();
			$myzc = $this->randzc();
			$keymain = $mydq.$myzc;
		}else if($keynum == 4){
			//词头+主词+词尾
			$myct = $this->randct();
			$myzc = $this->randzc();
			$mycw = $this->randcw();
			$keymain = $myct.$myzc.$mycw;
		}else if($keynum == 5){
			//地区+主词+词尾
			$mydq = $this->randdq();
			$myzc = $this->randzc();
			$mycw = $this->randcw();
			$keymain = $mydq.$myzc.$mycw;
		}else if($keynum == 6){
			//地区+词头+主词
			$mydq = $this->randdq();
			$myct = $this->randct();
			$myzc = $this->randzc();
			$keymain = $mydq.$myct.$myzc;
		}else if($keynum == 7){
			//地区+词头+主词
			$mydq = $this->randdq();
			$myct = $this->randct();
			$myzc = $this->randzc();
			$mycw = $this->randcw();
			$keymain = $mydq.$myct.$myzc.$mycw;
		}else{
			$keymain = "标题";
		}
		return $keymain;
	}
	
	/**
	 * 随机关键词  
	 * 主词,词头+主词,主词+词尾,词头+主词+词尾
	 */
	
	private function randomkeymain(){		
		$zca = $this->randzc();
		
		$ctb = $this->randct();
		$zcb = $this->randzc();
		$jub = $ctb.$zcb;
		
		$zcc = $this->randzc();
		$cwc = $this->randcw();
		$juc = $zcc.$cwc;
		
		$ctd = $this->randct();
		$zcd = $this->randzc();
		$cwd = $this->randcw();
		$jud = $ctd.$zcd.$cwd;
		
		//关键词拼接
		$keymain = "$zca,$jub,$juc,$jud";
		
		
		return $keymain;
	}
	
	
	/**
     * 随机文章描述
	 * 文章描述 $this->miaoshu
	 * 替换【diqu】【citou】【zhuci】【ciwei】【biaoti】
     */
	
	private function randommydesc(){	
		$mydesc = $this->miaoshu;
		$mynum = count($mydesc);
		$myrand = rand(1,$mynum)-1;
		$myinfo = $mydesc[$myrand];

		if(!empty($myinfo)){
			//替换标题
			$descdig = substr_count($myinfo,'【biaoti】');
			if($descdig > 0 ){
				for($des=0;$des<$descdig;$des++){
					$mybiaoti = $this->randbt();
					$myinfo = preg_replace('/【biaoti】/',$mybiaoti,$myinfo,1); 
				}
			}
			
			//替换地区
			$qdnum = substr_count($myinfo,'【diqu】');
			if($qdnum > 0){
				for($b=0;$b<$qdnum;$b++){
					$mydiqu = $this->randdq();
					$myinfo = preg_replace('/【diqu】/',$mydiqu,$myinfo,1); 
				}
			}
			//替换词头
			$ctnum = substr_count($myinfo,'【citou】');
			if($ctnum > 0){
				for($c=0;$c<$ctnum;$c++){
					$mycitou = $this->randct();
					$myinfo = preg_replace('/【citou】/',$mycitou,$myinfo,1); 
				}
			}
			//替换主词
			$zcnum = substr_count($myinfo,'【zhuci】');
			if($zcnum > 0){
				for($d=0;$d<$zcnum;$d++){
					$myzhuci = $this->randzc();
					$myinfo = preg_replace('/【zhuci】/',$myzhuci,$myinfo,1); 
				}
			}
			//替换词尾
			$cwnum = substr_count($myinfo,'【ciwei】');
			if($cwnum > 0){
				for($e=0;$e<$cwnum;$e++){
					$myciwei = $this->randcw();
					$myinfo = preg_replace('/【ciwei】/',$myciwei,$myinfo,1); 
				}
			}			
		}
		return $myinfo;
	} 
	
	/**
	 * 随机段落  
	 * 段落 $this->duanluo;
	 * 替换【diqu】【citou】【zhuci】【ciwei】【biaoti】
	 */
	
	private function randomdl(){
		//获取段落
		$duanluo = $this->duanluo;
		$dlnum = count($duanluo);
		$myrddl = rand(1,$dlnum)-1;
		$mydlinfo = $duanluo[$myrddl];
	    if(!empty($mydlinfo)){
			//替换标题
			$btdig = substr_count($mydlinfo,'【biaoti】');
			if($btdig > 0 ){
				for($a=0;$a<$btdig;$a++){
					$mybiaoti = $this->randbt();
					$mydlinfo = preg_replace('/【biaoti】/',$mybiaoti,$mydlinfo,1); 
				}
			}
			//替换地区
			$qdnum = substr_count($mydlinfo,'【diqu】');
			if($qdnum > 0){
				for($b=0;$b<$qdnum;$b++){
					$mydiqu = $this->randdq();
					$mydlinfo = preg_replace('/【diqu】/',$mydiqu,$mydlinfo,1); 
				}
			}
			//替换词头
			$ctnum = substr_count($mydlinfo,'【citou】');
			if($ctnum > 0){
				for($c=0;$c<$ctnum;$c++){
					$mycitou = $this->randct();
					$mydlinfo = preg_replace('/【citou】/',$mycitou,$mydlinfo,1); 
				}
			}
			//替换主词
			$zcnum = substr_count($mydlinfo,'【zhuci】');
			if($zcnum > 0){
				for($d=0;$d<$zcnum;$d++){
					$myzhuci = $this->randzc();
					$mydlinfo = preg_replace('/【zhuci】/',$myzhuci,$mydlinfo,1); 
				}
			}
			//替换词尾
			$cwnum = substr_count($mydlinfo,'【ciwei】');
			if($cwnum > 0){
				for($e=0;$e<$cwnum;$e++){
					$myciwei = $this->randcw();
					$mydlinfo = preg_replace('/【ciwei】/',$myciwei,$mydlinfo,1); 
				}
			}
			
		} 
		return $mydlinfo;
	}
	
	
	/**
	 *  随机句子
	 */
	
	private function randomjz(){
		$juzi = $this->juzi;
		$jznum = count($juzi);
		$rdjuzi = rand(1,$jznum) -1;
		$myjuzi = $juzi[$rdjuzi];
		return $myjuzi;
	}
	
	/**
	 * 随机图片
	 */
  
	private function randomtp(){
		$tupian = $this->tupian;
		$tpnum = count($tupian);
		if($tpnum >= 1 ){
			$rdtupian = rand(1,$tpnum)-1;
			$mytupian = $tupian[$rdtupian];
			//拼接路径
			$myphrases = "<img src='__PUBLIC__$mytupian' />";
			$myphrases = preg_replace('/\'/', '"', $myphrases);
			return $myphrases;
		}else{
			$myphrases = '';
			return $myphrases;
		}
		
	}
  
	/**
	 * 生成随机模板
	 */
	
 	private function randwz(){
		//获取模板
		$moban = $this->moban;
		$mbnum = count($moban);
		$rdnum = rand(1,$mbnum)-1;
		$rdmoban  = $moban[$rdnum];
		if(!empty($moban[$rdnum])){
			//替换【duanluo】
			$dlnum = substr_count($rdmoban,'【duanluo】');
			if($dlnum > 0){
				for($a=0;$a<$dlnum;$a++){
					$randomdl = $this->randomdl();
					$rdmoban = preg_replace('/【duanluo】/',$randomdl,$rdmoban,1); 
				}
			}
			//替换【juzi】
			$jznum = substr_count($rdmoban,'【juzi】');
			if($jznum > 0){
				for($b=0;$b<$jznum;$b++){
					$randomjz = $this->randomjz();
					$rdmoban = preg_replace('/【juzi】/',$randomjz,$rdmoban,1); 
				}
			}
			//替换【tupian】
			$tpnum = substr_count($rdmoban,'【tupian】');
			if($tpnum > 0){
				for($c=0;$c<$tpnum;$c++){
					$randomtp = $this->randomtp();
					$rdmoban = preg_replace('/【tupian】/',$randomtp,$rdmoban,1); 
				}
			}
			//替换【biaoti】
			$btnum = substr_count($rdmoban,'【biaoti】');
			if($btnum > 0){
				for($d=0;$d<$btnum;$d++){
					$randombt = $this->randbt();
					$rdmoban = preg_replace('/【biaoti】/',$randombt,$rdmoban,1); 
				}
			}
		}
		return $rdmoban;
	} 
	
}

